import { observable, action, toJS } from 'mobx';
import {WeaTableNew,WeaForm} from 'comsMobx';
import {WeaLocaleProvider} from 'ecCom';
import { message } from 'antd';
import * as API from "../../apis/task/authIndex";
const getLabel = WeaLocaleProvider.getLabel;
const { TableStore } = WeaTableNew;
export default class AuthStore {
    @observable tableStore = new TableStore(); // new table
    @observable searchAdForShareTable = {
      form: new WeaForm(),
      show: false,
      conditioninfo: []
    };
    @observable shareBaseDataType = {
      showObj: false,
      objCondition: [],
    };
    wtype = 1;
    @observable loading = false;

    @action("初始化")
    doInit(type){
        this.getSearchCondition();
        this.getAuthAddCondition();
        this.wtype = type;
        this.getTableDatas();
    }
    @action("渲染table数据")
    getTableDatas = () => {
        this.loading = true;
        let params = (this.searchAdForShareTable.form && this.searchAdForShareTable.form.getFormParams()) ||{};
        params.wtype = this.wtype;
        params.operate = "search";
        API.getAuthListOperate(params).then(action(res => {
            if (res.status) {
                this.tableStore.getDatas(res.datas, 1);
            } else {
                message.error(res.msg || getLabel('508818', '接口调用失败！'))
            }
            this.loading = false;
        }));
    };
    @action("权限高级搜索")
    getSearchCondition = () => {
        API.getAuthSearchCondition().then(res => {
        this.searchAdForShareTable.form.initFormFields(res.conditioninfo);
        this.searchAdForShareTable.conditioninfo = res.conditioninfo;
        });
    };
    @action("新增权限界面设置")
    getAuthAddCondition = params => {
        API.getAuthAddCondition(params).then(res => {
        this.shareBaseDataType.objCondition = res.conditioninfo;
        });
    };
    @action("新增权限界面显隐")
    setObjShow = (bool) => this.shareBaseDataType.showObj = bool;
    @action("新增权限")
    operatePermissions = (params) => {
        params.wtype = this.wtype;
        API.getAuthListOperate(params).then(res => {
          this.setObjShow(false);
          if(res.status){
            this.getTableDatas();
          }else {
            message.error(`${getLabel(30651, '操作失败')}`);
          }
        });
    };
}